home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_06 / saks / cat.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-08  |  657 b   |  31 lines

  1. Listing 11 - Corrections to the corrections to the string class that 
  2. appeared in Listing 9 of "Stepping Up to C++: Rewriting and 
  3. Reconsidering", CUJ, September, 1993.
  4.  
  5. //
  6. // append a nul-terminated string to a str
  7. //
  8. void str::cat(const char *s)
  9.     {
  10.     size_t n = len + strlen(s) + 1;
  11.     char *p = strcpy(new char[len], ptr);
  12.     strcat(p, s);
  13.     delete [] ptr;
  14.     ptr = p;
  15.     len = n - 1;    // the - 1 was missing
  16.     }
  17.  
  18. //
  19. // append a str to a str
  20. //
  21. void str::cat(const str &s)
  22.     {
  23.     size_t n = len + s.len + 1;
  24.     char *p = strcpy(new char[len], ptr);
  25.     strcat(p, s.ptr);
  26.     delete [] ptr;
  27.     ptr = p;
  28.     len = n - 1;    // the - 1 was missing
  29.     }
  30.  
  31.